home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / distutils / sysconfig.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  16.0 KB  |  515 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. """Provide access to Python's configuration information.  The specific
  5. configuration variables available depend heavily on the platform and
  6. configuration.  The values may be retrieved using
  7. get_config_var(name), and the list of variables is available via
  8. get_config_vars().keys().  Additional convenience functions are also
  9. available.
  10.  
  11. Written by:   Fred L. Drake, Jr.
  12. Email:        <fdrake@acm.org>
  13. """
  14. __revision__ = '$Id: sysconfig.py 69486 2009-02-10 12:33:42Z tarek.ziade $'
  15. import os
  16. import re
  17. import string
  18. import sys
  19. from distutils.errors import DistutilsPlatformError
  20. PREFIX = os.path.normpath(sys.prefix)
  21. EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
  22. project_base = os.path.dirname(os.path.abspath(sys.executable))
  23. if os.name == 'nt' and 'pcbuild' in project_base[-8:].lower():
  24.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir))
  25.  
  26. if os.name == 'nt' and '\\pc\\v' in project_base[-10:].lower():
  27.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, os.path.pardir))
  28.  
  29. if os.name == 'nt' and '\\pcbuild\\amd64' in project_base[-14:].lower():
  30.     project_base = os.path.abspath(os.path.join(project_base, os.path.pardir, os.path.pardir))
  31.  
  32.  
  33. def _python_build():
  34.     for fn in ('Setup.dist', 'Setup.local'):
  35.         if os.path.isfile(os.path.join(project_base, 'Modules', fn)):
  36.             return True
  37.     
  38.     return False
  39.  
  40. python_build = _python_build()
  41.  
  42. def get_python_version():
  43.     """Return a string containing the major and minor Python version,
  44.     leaving off the patchlevel.  Sample return values could be '1.5'
  45.     or '2.2'.
  46.     """
  47.     return sys.version[:3]
  48.  
  49.  
  50. def get_python_inc(plat_specific = 0, prefix = None):
  51.     """Return the directory containing installed Python header files.
  52.  
  53.     If 'plat_specific' is false (the default), this is the path to the
  54.     non-platform-specific header files, i.e. Python.h and so on;
  55.     otherwise, this is the path to platform-specific header files
  56.     (namely pyconfig.h).
  57.  
  58.     If 'prefix' is supplied, use it instead of sys.prefix or
  59.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  60.     """
  61.     if prefix is None:
  62.         if not plat_specific or EXEC_PREFIX:
  63.             pass
  64.         prefix = PREFIX
  65.     
  66.     if os.name == 'posix':
  67.         if python_build:
  68.             base = os.path.dirname(os.path.abspath(sys.executable))
  69.             if plat_specific:
  70.                 inc_dir = base
  71.             else:
  72.                 inc_dir = os.path.join(base, 'Include')
  73.                 if not os.path.exists(inc_dir):
  74.                     inc_dir = os.path.join(os.path.dirname(base), 'Include')
  75.                 
  76.             return inc_dir
  77.         if not sys.pydebug or '_d':
  78.             pass
  79.         return os.path.join(prefix, 'include', 'python' + get_python_version() + '')
  80.     if os.name == 'nt':
  81.         return os.path.join(prefix, 'include')
  82.     if os.name == 'mac':
  83.         if plat_specific:
  84.             return os.path.join(prefix, 'Mac', 'Include')
  85.         return os.path.join(prefix, 'Include')
  86.     os.name == 'mac'
  87.     if os.name == 'os2':
  88.         return os.path.join(prefix, 'Include')
  89.     raise DistutilsPlatformError("I don't know where Python installs its C header files on platform '%s'" % os.name)
  90.  
  91.  
  92. def get_python_lib(plat_specific = 0, standard_lib = 0, prefix = None):
  93.     """Return the directory containing the Python library (standard or
  94.     site additions).
  95.  
  96.     If 'plat_specific' is true, return the directory containing
  97.     platform-specific modules, i.e. any module from a non-pure-Python
  98.     module distribution; otherwise, return the platform-shared library
  99.     directory.  If 'standard_lib' is true, return the directory
  100.     containing standard Python library modules; otherwise, return the
  101.     directory for site-specific modules.
  102.  
  103.     If 'prefix' is supplied, use it instead of sys.prefix or
  104.     sys.exec_prefix -- i.e., ignore 'plat_specific'.
  105.     """
  106.     if not not prefix:
  107.         pass
  108.     is_default_prefix = os.path.normpath(prefix) in ('/usr', '/usr/local')
  109.     if prefix is None:
  110.         if not plat_specific or EXEC_PREFIX:
  111.             pass
  112.         prefix = PREFIX
  113.     
  114.     if os.name == 'posix':
  115.         libpython = os.path.join(prefix, 'lib', 'python' + get_python_version())
  116.         if standard_lib:
  117.             return libpython
  118.         if is_default_prefix and 'PYTHONUSERBASE' not in os.environ and 'real_prefix' not in sys.__dict__:
  119.             return os.path.join(libpython, 'dist-packages')
  120.         return os.path.join(libpython, 'site-packages')
  121.     os.name == 'posix'
  122.     if os.name == 'nt':
  123.         if standard_lib:
  124.             return os.path.join(prefix, 'Lib')
  125.         if get_python_version() < '2.2':
  126.             return prefix
  127.         return os.path.join(prefix, 'Lib', 'site-packages')
  128.     os.name == 'nt'
  129.     if os.name == 'mac':
  130.         if plat_specific:
  131.             if standard_lib:
  132.                 return os.path.join(prefix, 'Lib', 'lib-dynload')
  133.             return os.path.join(prefix, 'Lib', 'site-packages')
  134.         plat_specific
  135.         if standard_lib:
  136.             return os.path.join(prefix, 'Lib')
  137.         return os.path.join(prefix, 'Lib', 'site-packages')
  138.     os.name == 'mac'
  139.     if os.name == 'os2':
  140.         if standard_lib:
  141.             return os.path.join(prefix, 'Lib')
  142.         return os.path.join(prefix, 'Lib', 'site-packages')
  143.     os.name == 'os2'
  144.     raise DistutilsPlatformError("I don't know where Python installs its library on platform '%s'" % os.name)
  145.  
  146.  
  147. def customize_compiler(compiler):
  148.     """Do any platform-specific customization of a CCompiler instance.
  149.  
  150.     Mainly needed on Unix, so we can plug in the information that
  151.     varies across Unices and is stored in Python's Makefile.
  152.     """
  153.     if compiler.compiler_type == 'unix':
  154.         (cc, cxx, opt, cflags, opt, extra_cflags, basecflags, ccshared, ldshared, so_ext) = get_config_vars('CC', 'CXX', 'OPT', 'CFLAGS', 'OPT', 'EXTRA_CFLAGS', 'BASECFLAGS', 'CCSHARED', 'LDSHARED', 'SO')
  155.         if 'CC' in os.environ:
  156.             cc = os.environ['CC']
  157.         
  158.         if 'CXX' in os.environ:
  159.             cxx = os.environ['CXX']
  160.         
  161.         if 'LDSHARED' in os.environ:
  162.             ldshared = os.environ['LDSHARED']
  163.         
  164.         if 'CPP' in os.environ:
  165.             cpp = os.environ['CPP']
  166.         else:
  167.             cpp = cc + ' -E'
  168.         if 'LDFLAGS' in os.environ:
  169.             ldshared = ldshared + ' ' + os.environ['LDFLAGS']
  170.         
  171.         if 'BASECFLAGS' in os.environ:
  172.             basecflags = os.environ['BASECFLAGS']
  173.         
  174.         if 'OPT' in os.environ:
  175.             opt = os.environ['OPT']
  176.         
  177.         cflags = ' '.join((lambda .0: for x in .0:
  178. if x:
  179. str(x)continue)((basecflags, opt, extra_cflags)))
  180.         if 'CFLAGS' in os.environ:
  181.             cflags = ' '.join((lambda .0: for x in .0:
  182. if x:
  183. str(x)continue)((basecflags, opt, os.environ['CFLAGS'], extra_cflags)))
  184.             ldshared = ldshared + ' ' + os.environ['CFLAGS']
  185.         
  186.         if 'CPPFLAGS' in os.environ:
  187.             cpp = cpp + ' ' + os.environ['CPPFLAGS']
  188.             cflags = cflags + ' ' + os.environ['CPPFLAGS']
  189.             ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
  190.         
  191.         cc_cmd = cc + ' ' + cflags
  192.         compiler.set_executables(preprocessor = cpp, compiler = cc_cmd, compiler_so = cc_cmd + ' ' + ccshared, compiler_cxx = cxx, linker_so = ldshared, linker_exe = cc)
  193.         compiler.shared_lib_extension = so_ext
  194.     
  195.  
  196.  
  197. def get_config_h_filename():
  198.     '''Return full pathname of installed pyconfig.h file.'''
  199.     if python_build:
  200.         if os.name == 'nt':
  201.             inc_dir = os.path.join(project_base, 'PC')
  202.         else:
  203.             inc_dir = project_base
  204.     else:
  205.         inc_dir = get_python_inc(plat_specific = 1)
  206.     if get_python_version() < '2.2':
  207.         config_h = 'config.h'
  208.     else:
  209.         config_h = 'pyconfig.h'
  210.     return os.path.join(inc_dir, config_h)
  211.  
  212.  
  213. def get_makefile_filename():
  214.     '''Return full pathname of installed Makefile from the Python build.'''
  215.     if python_build:
  216.         return os.path.join(os.path.dirname(sys.executable), 'Makefile')
  217.     lib_dir = get_python_lib(plat_specific = 1, standard_lib = 1)
  218.     if not sys.pydebug or '_d':
  219.         pass
  220.     return os.path.join(lib_dir, 'config' + '', 'Makefile')
  221.  
  222.  
  223. def parse_config_h(fp, g = None):
  224.     '''Parse a config.h-style file.
  225.  
  226.     A dictionary containing name/value pairs is returned.  If an
  227.     optional dictionary is passed in as the second argument, it is
  228.     used instead of a new dictionary.
  229.     '''
  230.     if g is None:
  231.         g = { }
  232.     
  233.     define_rx = re.compile('#define ([A-Z][A-Za-z0-9_]+) (.*)\n')
  234.     undef_rx = re.compile('/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n')
  235.     while None:
  236.         line = fp.readline()
  237.         if not line:
  238.             break
  239.         
  240.         m = define_rx.match(line)
  241.         if m:
  242.             (n, v) = m.group(1, 2)
  243.             
  244.             try:
  245.                 v = int(v)
  246.             except ValueError:
  247.                 pass
  248.  
  249.             g[n] = v
  250.             continue
  251.         m = undef_rx.match(line)
  252.         if m:
  253.             g[m.group(1)] = 0
  254.             continue
  255.         continue
  256.         return g
  257.  
  258. _variable_rx = re.compile('([a-zA-Z][a-zA-Z0-9_]+)\\s*=\\s*(.*)')
  259. _findvar1_rx = re.compile('\\$\\(([A-Za-z][A-Za-z0-9_]*)\\)')
  260. _findvar2_rx = re.compile('\\${([A-Za-z][A-Za-z0-9_]*)}')
  261.  
  262. def parse_makefile(fn, g = None):
  263.     '''Parse a Makefile-style file.
  264.  
  265.     A dictionary containing name/value pairs is returned.  If an
  266.     optional dictionary is passed in as the second argument, it is
  267.     used instead of a new dictionary.
  268.     '''
  269.     TextFile = TextFile
  270.     import distutils.text_file
  271.     fp = TextFile(fn, strip_comments = 1, skip_blanks = 1, join_lines = 1)
  272.     if g is None:
  273.         g = { }
  274.     
  275.     done = { }
  276.     notdone = { }
  277.     while None:
  278.         line = fp.readline()
  279.         if line is None:
  280.             break
  281.         
  282.         m = _variable_rx.match(line)
  283.         if m:
  284.             (n, v) = m.group(1, 2)
  285.             v = string.strip(v)
  286.             if '$' in v:
  287.                 notdone[n] = v
  288.             else:
  289.                 
  290.                 try:
  291.                     v = int(v)
  292.                 except ValueError:
  293.                     pass
  294.  
  295.                 done[n] = v
  296.         continue
  297.         while notdone:
  298.             for name in notdone.keys():
  299.                 value = notdone[name]
  300.                 if not _findvar1_rx.search(value):
  301.                     pass
  302.                 m = _findvar2_rx.search(value)
  303.                 if m:
  304.                     n = m.group(1)
  305.                     found = True
  306.                     if n in done:
  307.                         item = str(done[n])
  308.                     elif n in notdone:
  309.                         found = False
  310.                     elif n in os.environ:
  311.                         item = os.environ[n]
  312.                     else:
  313.                         done[n] = item = ''
  314.                     if found:
  315.                         after = value[m.end():]
  316.                         value = value[:m.start()] + item + after
  317.                         if '$' in after:
  318.                             notdone[name] = value
  319.                         else:
  320.                             
  321.                             try:
  322.                                 value = int(value)
  323.                             except ValueError:
  324.                                 done[name] = string.strip(value)
  325.  
  326.                             done[name] = value
  327.                             del notdone[name]
  328.                     
  329.                 found
  330.                 del notdone[name]
  331.             
  332.         fp.close()
  333.         g.update(done)
  334.         return g
  335.  
  336.  
  337. def expand_makefile_vars(s, vars):
  338.     '''Expand Makefile-style variables -- "${foo}" or "$(foo)" -- in
  339.     \'string\' according to \'vars\' (a dictionary mapping variable names to
  340.     values).  Variables not present in \'vars\' are silently expanded to the
  341.     empty string.  The variable values in \'vars\' should not contain further
  342.     variable expansions; if \'vars\' is the output of \'parse_makefile()\',
  343.     you\'re fine.  Returns a variable-expanded version of \'s\'.
  344.     '''
  345.     while not _findvar1_rx.search(s):
  346.         m = _findvar2_rx.search(s)
  347.         if m:
  348.             (beg, end) = m.span()
  349.             s = s[0:beg] + vars.get(m.group(1)) + s[end:]
  350.             continue
  351.     break
  352.     continue
  353.     return s
  354.  
  355. _config_vars = None
  356.  
  357. def _init_posix():
  358.     '''Initialize the module as appropriate for POSIX systems.'''
  359.     global _config_vars
  360.     g = { }
  361.     
  362.     try:
  363.         filename = get_makefile_filename()
  364.         parse_makefile(filename, g)
  365.     except IOError:
  366.         msg = None
  367.         my_msg = 'invalid Python installation: unable to open %s' % filename
  368.         if hasattr(msg, 'strerror'):
  369.             my_msg = my_msg + ' (%s)' % msg.strerror
  370.         
  371.         raise DistutilsPlatformError(my_msg)
  372.  
  373.     
  374.     try:
  375.         filename = get_config_h_filename()
  376.         parse_config_h(file(filename), g)
  377.     except IOError:
  378.         msg = None
  379.         my_msg = 'invalid Python installation: unable to open %s' % filename
  380.         if hasattr(msg, 'strerror'):
  381.             my_msg = my_msg + ' (%s)' % msg.strerror
  382.         
  383.         raise DistutilsPlatformError(my_msg)
  384.  
  385.     if sys.platform == 'darwin' and 'MACOSX_DEPLOYMENT_TARGET' in g:
  386.         cfg_target = g['MACOSX_DEPLOYMENT_TARGET']
  387.         cur_target = os.getenv('MACOSX_DEPLOYMENT_TARGET', '')
  388.         if cur_target == '':
  389.             cur_target = cfg_target
  390.             os.putenv('MACOSX_DEPLOYMENT_TARGET', cfg_target)
  391.         elif map(int, cfg_target.split('.')) > map(int, cur_target.split('.')):
  392.             my_msg = '$MACOSX_DEPLOYMENT_TARGET mismatch: now "%s" but "%s" during configure' % (cur_target, cfg_target)
  393.             raise DistutilsPlatformError(my_msg)
  394.         
  395.     
  396.     if python_build:
  397.         g['LDSHARED'] = g['BLDSHARED']
  398.     elif get_python_version() < '2.1':
  399.         if sys.platform == 'aix4':
  400.             python_lib = get_python_lib(standard_lib = 1)
  401.             ld_so_aix = os.path.join(python_lib, 'config', 'ld_so_aix')
  402.             python_exp = os.path.join(python_lib, 'config', 'python.exp')
  403.             g['LDSHARED'] = '%s %s -bI:%s' % (ld_so_aix, g['CC'], python_exp)
  404.         elif sys.platform == 'beos':
  405.             python_lib = get_python_lib(standard_lib = 1)
  406.             linkerscript_path = string.split(g['LDSHARED'])[0]
  407.             linkerscript_name = os.path.basename(linkerscript_path)
  408.             linkerscript = os.path.join(python_lib, 'config', linkerscript_name)
  409.             g['LDSHARED'] = '%s -L%s/lib -lpython%s' % (linkerscript, PREFIX, get_python_version())
  410.         
  411.     
  412.     _config_vars = g
  413.  
  414.  
  415. def _init_nt():
  416.     '''Initialize the module as appropriate for NT'''
  417.     global _config_vars
  418.     g = { }
  419.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  420.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  421.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  422.     g['SO'] = '.pyd'
  423.     g['EXE'] = '.exe'
  424.     g['VERSION'] = get_python_version().replace('.', '')
  425.     g['BINDIR'] = os.path.dirname(os.path.abspath(sys.executable))
  426.     _config_vars = g
  427.  
  428.  
  429. def _init_mac():
  430.     '''Initialize the module as appropriate for Macintosh systems'''
  431.     global _config_vars
  432.     g = { }
  433.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  434.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  435.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  436.     import MacOS
  437.     if not hasattr(MacOS, 'runtimemodel'):
  438.         g['SO'] = '.ppc.slb'
  439.     else:
  440.         g['SO'] = '.%s.slb' % MacOS.runtimemodel
  441.     g['install_lib'] = os.path.join(EXEC_PREFIX, 'Lib')
  442.     g['install_platlib'] = os.path.join(EXEC_PREFIX, 'Mac', 'Lib')
  443.     g['srcdir'] = ':'
  444.     _config_vars = g
  445.  
  446.  
  447. def _init_os2():
  448.     '''Initialize the module as appropriate for OS/2'''
  449.     global _config_vars
  450.     g = { }
  451.     g['LIBDEST'] = get_python_lib(plat_specific = 0, standard_lib = 1)
  452.     g['BINLIBDEST'] = get_python_lib(plat_specific = 1, standard_lib = 1)
  453.     g['INCLUDEPY'] = get_python_inc(plat_specific = 0)
  454.     g['SO'] = '.pyd'
  455.     g['EXE'] = '.exe'
  456.     _config_vars = g
  457.  
  458.  
  459. def get_config_vars(*args):
  460.     """With no arguments, return a dictionary of all configuration
  461.     variables relevant for the current platform.  Generally this includes
  462.     everything needed to build extensions and install both pure modules and
  463.     extensions.  On Unix, this means every variable defined in Python's
  464.     installed Makefile; on Windows and Mac OS it's a much smaller set.
  465.  
  466.     With arguments, return a list of values that result from looking up
  467.     each argument in the configuration variable dictionary.
  468.     """
  469.     global _config_vars
  470.     if _config_vars is None:
  471.         func = globals().get('_init_' + os.name)
  472.         if func:
  473.             func()
  474.         else:
  475.             _config_vars = { }
  476.         _config_vars['prefix'] = PREFIX
  477.         _config_vars['exec_prefix'] = EXEC_PREFIX
  478.         if sys.platform == 'darwin':
  479.             kernel_version = os.uname()[2]
  480.             major_version = int(kernel_version.split('.')[0])
  481.             if major_version < 8:
  482.                 for key in ('LDFLAGS', 'BASECFLAGS', 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  483.                     flags = _config_vars[key]
  484.                     flags = re.sub('-arch\\s+\\w+\\s', ' ', flags)
  485.                     flags = re.sub('-isysroot [^ \t]*', ' ', flags)
  486.                     _config_vars[key] = flags
  487.                 
  488.             elif 'ARCHFLAGS' in os.environ:
  489.                 arch = os.environ['ARCHFLAGS']
  490.                 for key in ('LDFLAGS', 'BASECFLAGS', 'CFLAGS', 'PY_CFLAGS', 'BLDSHARED'):
  491.                     flags = _config_vars[key]
  492.                     flags = re.sub('-arch\\s+\\w+\\s', ' ', flags)
  493.                     flags = flags + ' ' + arch
  494.                     _config_vars[key] = flags
  495.                 
  496.             
  497.         
  498.     
  499.     if args:
  500.         vals = []
  501.         for name in args:
  502.             vals.append(_config_vars.get(name))
  503.         
  504.         return vals
  505.     return _config_vars
  506.  
  507.  
  508. def get_config_var(name):
  509.     """Return the value of a single variable using the dictionary
  510.     returned by 'get_config_vars()'.  Equivalent to
  511.     get_config_vars().get(name)
  512.     """
  513.     return get_config_vars().get(name)
  514.  
  515.